/**
 * Created by DevilsEyes on 2015/12/17.
 */
(function (p) {
    var core = function () {
        var i,
            codeOrder = '~@$%^*?!#+-=&._:;,<>(){}[]/|\'\"\\',
            RepString = 'TtE_g',
            encodeDict = {}, decodeDict = {};

        for (i = 0; i < codeOrder.length; i++) {
            encodeDict[codeOrder[i]] = RepString.replace(/_/g, "" + i);
            decodeDict[RepString.replace(/_/g, "" + i)] = codeOrder[i];
        }

        function Encoder() {
            this.encode = function (str) {
                for (var e in encodeDict) {
                    str = str.replace(new RegExp('\\' + e, 'g'), encodeDict[e]);
                }
                return str;
            };
            this.decode = function (str) {
                for (var e in decodeDict) {
                    str = str.replace(new RegExp('\\' + e, 'g'), decodeDict[e]);
                }
                return str;
            };
            this.urlEncode = function (str) {
                return encodeURIComponent(this.encode(str));
            };
            this.urlDecode = function (str) {
                return this.decode(decodeURIComponent(str));
            };
        }
        return new Encoder();
    };
    if (typeof define == 'function' && define.amd) {
        define(function () {
            var iNEncoder = core();
            return iNEncoder;
        })
    } else {
        p.iNEncoder = core();
    }
})(window);